﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Outputs Labels in view mode and CheckBoxes in edit mode.
	/// </summary>
	public class CheckBoxColumn : BaseDataColumn
	{
		/// <summary>
		/// Creates the view mode Label.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="owner"></param>
		public override void CreateViewItem(System.Web.UI.Control container, Grid owner)
		{
			if (string.IsNullOrEmpty(ViewControl.Id))
				ViewControl.Id = "lbl" + Regex.Replace(this.Data.Field, "[^\\w]", "");
			Label l = new Label
			{
				ID = ViewControl.Id,
				CssClass = ViewControl.CssClass
			};
			l.Data.Set(Data);
			l.Attributes["style"] = ViewControl.Style;
			container.Controls.Add(l);
		}
		/// <summary>
		/// Creates the edit mode CheckBox.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="owner"></param>
		public override void CreateEditItem(System.Web.UI.Control container, Grid owner)
		{
			if (string.IsNullOrEmpty(EditControl.Id))
				EditControl.Id = "chk" + Regex.Replace(this.Data.Field, "[^\\w]", "");
			CheckBox t = new CheckBox
			{
				ID = EditControl.Id,
				CssClass = EditControl.CssClass
			};
			t.Data.Set(Data);
			t.Attributes["style"] = EditControl.Style;
			container.Controls.Add(t);
		}
		/// <summary>
		/// Creates the validators, if any.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="field"></param>
		protected void CreateValidators(Control container, TControl field)
		{
		}
	}
}
